<template>
  <div class="container">
    <div class="title">
      <span>新增合同</span>
      <span class="back" @click="back"> <i class="iconfont icon-fanhui"></i> 返回 </span>
    </div>
    <el-divider></el-divider>
    <div class="wrap">
      <el-row>
        <el-col :lg="16" :md="20" :sm="24" :xs="24">
          <el-form :model="form" status-icon ref="form" label-width="100px" v-loading="loading" @submit.native.prevent>
            <el-form-item label="合同名称" prop="contractname">
              <el-input size="medium" v-model="form.contractname" placeholder="请填写合同名称"></el-input>
            </el-form-item>
            <el-form-item label="甲方" prop="firstname">
              <el-input size="medium" v-model="form.firstname" placeholder="请填写甲方"></el-input>
            </el-form-item>
            <el-form-item label="甲方电话" prop="firstphone">
              <el-input size="medium" v-model="form.firstphone" placeholder="请填写甲方电话"></el-input>
            </el-form-item>
            <el-form-item label="乙方" prop="secname">
              <el-input size="medium" v-model="form.secname" placeholder="请填写乙方"></el-input>
            </el-form-item>
            <el-form-item label="乙方" prop="secphone">
              <el-input size="medium" v-model="form.secphone" placeholder="请填写乙方电话"></el-input>
            </el-form-item>
            <el-form-item class="submit">
              <el-button type="primary" @click="submitForm('form')">保 存</el-button>
              <el-button @click="resetForm('form')">重 置</el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import book from '@/model/book'
import Contract from '@/model/contract'

export default {
  props: {
    editBookID: {
      type: Number,
    },
  },
  data() {
    return {
      loading: false,
      form: {},
    }
  },
  async mounted() {
    this.loading = true
    // this.form = await book.getBook(this.editBookID)
    this.loading = false
  },
  methods: {
    async submitForm() {
      const obj = {
        Opcode: '111',
        data: {
          ...this.form,
        },
      }
      const res = await Contract.contractinfoadd(obj)
      console.log(res)
      if (res.success == true) {
        this.$message('生成成功')
        this.$emit('editClose')
      }
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    back() {
      this.$emit('editClose')
    },
  },
}
</script>

<style lang="scss" scoped>
.el-divider--horizontal {
  margin: 0;
}

.container {
  .title {
    height: 59px;
    line-height: 59px;
    color: $parent-title-color;
    font-size: 16px;
    font-weight: 500;
    text-indent: 40px;

    .back {
      float: right;
      margin-right: 40px;
      cursor: pointer;
    }
  }

  .wrap {
    padding: 20px;
  }

  .submit {
    float: left;
  }
}
</style>
